/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-10-10 16:25:31
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-11-04 10:36:32
 * @FilePath: \实训二——宏业找房\egg\app\controller\home.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
'use strict';

const { Controller } = require('egg');
class MessageController extends Controller {
    // 经纪人获取二手房源数据
    async agentMessage() {
        const { ctx } = this;
        const results = await this.app.mysql.select('message');
        if (results) {
            ctx.body = {
                code: 200,
                msg: '获取成功',
                list:results
            }
        } else {
            ctx.body = {
                code: 500,
                msg: '获取失败'
            }
        }
    }
    // 经纪人获取二手房源数据
    async delAgentMessage() {
        const { ctx } = this;
        const {id}=ctx.request.body;
        const results = await this.app.mysql.delete('message', { id });
        
        if (results) {
            const list = await this.app.mysql.select('message');
            ctx.body = {
                code: 200,
                msg: '删除成功',
                list
            }
        } else {
            ctx.body = {
                code: 500,
                msg: '删除失败'
            }
        }
    }
}

module.exports = MessageController;
